<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    ul {
      display: none;
    }
    .show {
      display: block;
    }
  </style>
  <body>
    <div>
      <h4>一级</h4>
      <ul>
        <li>二级1</li>
        <li>二级2</li>
      </ul>
    </div>
    <div>
      <h4>一级</h4>
      <ul>
        <li>二级1</li>
        <li>二级2</li>
      </ul>
    </div>
    //====================
    <script>
      const h4 = document.querySelectorAll("h4");
      //   const ul = document.querySelectorAll("ul");
      //   h4.addEventListener("click", function () {
      //     ul.classList.toggle("show");
      //   });
      h4.forEach((h4) => {
        //拿到每一个会H4
        h4.addEventListener("click", function () {
          h4.nextElementSibling.classList.toggle("show");
        });
      });
    </script>
  </body>
</html>
